﻿@using vITs.Site.Models.DataModels
@{this.ViewBag.Title = "Granska Uppdrag";}
<h2>@this.ViewBag.Title</h2>
@{
    this.Html.RenderAction("ViewAssignment", "Assignment", new { AssignmentId = this.ViewBag.Assignment.AssignmentId });
}
@if (VitsExtensionMethods.GetStatus(this.ViewBag.Assignment) == AssignmentStatus.AssignmentApproved)
{
    <script type="text/javascript">
        function requestAdvance () {
            var advance = prompt("Ange förskottssumma:", "0");

            $.ajax({
                url: '@String.Format("{0}?AssignmentId={1}", this.Url.Action("RequestAdvance","Assignment"), this.ViewBag.Assignment.AssignmentId)' + '&advance=' + advance,
                success: function(data) {
                    if (data.error != undefined)
                    {
                        alert(data.error);
                    } else {
                        alert(data.msg);
                    }

                    window.location = data.url;
                }
            });
        }
    </script>
    <input type="button" value="Ansök om förskott" onclick="javascript:requestAdvance();" />
}

@if (this.ViewBag.IsEditable)
{
    <br />
    
    <a href="@Url.Action("AddTrip", "Assignment", new { AssignmentId = this.ViewBag.Assignment.AssignmentId })">Lägg till Resa</a>
    
    <a href="@Url.Action("AddPerDiem", "Assignment", new { AssignmentId = this.ViewBag.Assignment.AssignmentId })">Lägg till Traktamente</a>
    
    <a href="@Url.Action("AddExpense", "Assignment", new { AssignmentId = this.ViewBag.Assignment.AssignmentId })">Lägg till Utgift</a>

    <a href="@Url.Action("CreateVacation", "Vacation", new { AssignmentId = this.ViewBag.Assignment.AssignmentId })">Lägg til Uppehåll</a>
    
    <a href="@Url.Action("SubmitAssignment", "Assignment", new { AssignmentId = this.ViewBag.Assignment.AssignmentId })">Ansök om slutgiltig bekräftelse</a>
}